home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9423 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with Watcom C++ 10.5
  5. Date: Sun, 10 Mar 96 14:20:06 GMT
  6. Organization: none
  7. Message-ID: <826467606snz@genesis.demon.co.uk>
  8. References: <31426ACB.6AA1@scsn.net>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <31426ACB.6AA1@scsn.net> mdorsey@scsn.net "Michael" writes:
  15.  
  16. >I'm having a rather strange problem with Watcom C.  When using functions
  17. >that output to stdout (ie printf()), it is not flushing to the screen
  18. >until a newline is sent.  For example:
  19. >
  20. >void main(void)
  21.  
  22. If you want your program to mean anything write that as int main(void)
  23. void main(void) simply means that the whole program has no defined behaviour.
  24.  
  25. >{
  26. >  printf("Hit Y for yes, N for no: ");
  27. >  yn();
  28.  
  29. And put here:
  30.  
  31.    return 0;
  32. >}
  33. >
  34. >
  35. >yn() gets the key stroke and prints yes or no.  The problem is that the
  36. >statement will not be printed until the newline from the answer is sent.
  37.  
  38. This is quite normal and indicates that Watcom defaults to line buffering
  39. on stdout when it is connected to the terminal. A correct program can't
  40. assume that output buffers will be flushed when you read input. You can
  41. usually assume that output to an 'interactive device' such as your terminal
  42. will be flushed when a newline is written, however a C implementation isn't
  43. even required to do this if it provides suitable documentation.
  44.  
  45. >Kind of hard to answer a question if you can't see it.  I can get around
  46. >it by flushing stdout after printf(), but I was kind of hoping there was
  47. >some type of variable I could set to turn off buffering of stdout.
  48.  
  49. In your code above you must either ensure that stdout is not buffered by
  50. calling setbuf() or setvbuf() at the start of the program. However
  51. fflush(stdout) is probably a better solution since you don't lose buffering.
  52. It isn't likely to be a significant code overhead in your program. As well
  53. as putting it after printf() you might also be able to put it into your
  54. input functions such as yn().
  55.  
  56. -- 
  57. -----------------------------------------
  58. Lawrence Kirby | fred@genesis.demon.co.uk
  59. Wilts, England | 70734.126@compuserve.com
  60. -----------------------------------------
  61.